package cate.game.play.skill.passive.guild;

import cate.common.table.d.GDAttr;
import cate.common.table.d.GDBuff;
import cate.game.attr.FightAttr;
import cate.game.play.base.HpCfg;
import cate.game.play.base.TargetFilterParam;
import cate.game.play.base.TargetSelector;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.skill.FighterCD;
import cate.game.play.skill.effect.SkillEffect;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 每攻击3次，对敌方随机1个目标造成10%最大生命值的伤害；
 * 对拥有护盾的目标额外造成6%的伤害并且伤害无视60%的护盾
 */
public class 九幽阴魂PH extends PassiveHandler {

	private int 次数;

	private HpCfg 血量配置;

	private double 额外伤害;

	private double 无视比例;

	private int 冷却回合;

	//次数=3&血量配置=？？&额外伤害=600&无视比例=6000&冷却回合=1
	@Override
	public void parse(String code) {
		PlayCfgArgs args= new PlayCfgArgs(code);
		次数 = args.getInt("次数", 0);
		血量配置 = new HpCfg(args);
		额外伤害 = args.getDouble("额外伤害", 0d);
		无视比例 = args.getDouble("无视比例", 0d);
		冷却回合 = args.getInt("冷却回合", 0);
	}

	private int num;

	private int lastSettleRound;

	@Override
	public void afterOneAttack(SkillActionCtx action, long totalDamage, boolean strike, Fighter target) {
		if (FighterCD.inCD(lastSettleRound, 冷却回合, action.getRound().index)) {
			return;
		}
		num++;
		if (num >= 次数) {
			Fighter one = TargetSelector.findOne(skill.owner, action.getTeamVs(), new TargetFilterParam());
			if (one != null) {
				num = 0;
				lastSettleRound = action.getRound().index;
				double v = 血量配置.settle(skill.owner, one);
				one.attr.buffHurt(action, skill.owner, v);
			}
		}
	}

	@Override
	public void beforeSkillSettleAsActor(SkillActionCtx action, SkillEffect effect, Fighter target) {
		if (target.buff.containType(GDBuff.Type.护盾)) {
			effect.getTargetCtx(target.getPid()).addActorAttr(new FightAttr(GDAttr.DAMAGE_ADD, 额外伤害));
			effect.getTargetCtx(target.getPid()).addIgnShieldRate(无视比例);
		}
	}
}
